<?php

namespace Common\Controller\CommonActions;
use Common\Controller\BaseController;

class OrgnizerActionController extends BaseController
{
    /**
     * 返回组织者信息列表
     * @return array
     */
    static public function showOrgnizersInfo()
    {
        return D('Common/Orgnizers')->showOrgnizersInfo();
    }

    /**
     * 输入班级组织信息返回用户列表数组
     * @param $queryJsonData
     * @return array
     */
    static public function getUserList($oid, $queryJsonData)
    {
        return D('Common/Orgnizeruserclass')->getUserList($oid, $queryJsonData);
    }

    /**
     * 输出oid对应组织名称
     * @param $oid
     * @return string
     */

    static public function getOrgnizerName($oid)
    {
        return D('Common/Orgnizers')->showOrgnizerName($oid);
    }

    /**
     * 更新对应oid的组织结构信息
     * @param $oid
     * @param $jsondata
     * @return mixed
     */

    static public function updateClassInfo($oid,$jsondata)
    {
        return D('Common/Orgnizers')->updateClassInfo($oid, $jsondata);
    }

    /**
     * 更新用户信息
     * @param $uid
     * @param $dataarr
     * @return array
     */
    static public function updateUserinfo($uid, $dataarr)
    {
        if (!$dataarr['username'])
            unset($dataarr['username']);
        if(!$dataarr['email'])
            unset($dataarr['email']);
        if(!$dataarr['password'])
            unset($dataarr['password']);

        if (!$dataarr){
            $rs['msg'] = '没有信息被修改';
            return $rs;
        }
        else{
            return D('Common/Users')->updateUserInfo($uid, $dataarr);
        }

    }

    /**
     * 批量添加用户（json格式）
     * @param $userjsondata
     * @param $classjsondata
     * @return mixed
     */
    static public function addJsonUserData($userjsondata, $classjsondata, $oid)
    {
        $userlist = json_decode($userjsondata, true);
        return D('Common/Users')->addOrgnizerUsers($userlist[0], $classjsondata, $oid);
    }

    /**
     * 获得组织者组织结构树形数据
     * @param $oid
     * @return jsonstr
     */

    static public function getClassInfoTree($oid)
    {
        return D('Common/Orgnizers')->getClassInfoTree($oid);
    }

    /**
     * 批量删除用户
     * @param $userlistjsondata
     * @return mixed
     */

    static public function deleteUsers($userlistjsondata)
    {
        $userlist = json_decode($userlistjsondata, true);

        $M = D('Common/Users');
        return $M->deleteUsers($userlist);
    }

    static public function getClassArray($oid)
    {
        $array = D('Common/Orgnizers')->getClassInfoTreeArray($oid);
        return $array;

    }


}
